package cc.rico.tutorial.helloworld;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import cc.rico.tutorial.RabbitMQConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.extern.slf4j.Slf4j;

/**
 * @author rico 2017年6月26日
 *
 */
@Slf4j
public class Send {
	private static final String QUEUE_NAME = "helloworld";
	
	public static void main(String[] args) throws IOException, TimeoutException {
		Connection conn = RabbitMQConnectionUtil.getConnection();
		Channel channel = conn.createChannel();
		
		// queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments)
		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		String message = "Hello World";
		channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
		log.info("[X] sent.message={}", message);

		RabbitMQConnectionUtil.close(conn, channel);
	}
}
